package com.ly.weixmesg.utils;

import com.ly.weixmesg.dto.Weather;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;

import java.util.Map;


/**
 * @author LBG
 * @creat 2022-09-04-8:42
 */
public class Pusher {
    private static String appId = "wxe4f711b25956047a";
    private static String secret = "5a3d9216d85878f728d7c0c0f352cacf";


    public static void push(){
        //1，配置
        WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
        wxStorage.setAppId(appId);
        wxStorage.setSecret(secret);
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxStorage);
        //2,推送消息
        WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                .toUser("osEGp5rn_Q4D1bKcZG6ca-I6Ii_A")//用户id
                .templateId("MbQ-OejlX3Svcco9ZPUQU9ivkOrUDJnzaJqU_0eq0AI")//模板id
                .build();

        String caiHongPi = CaiHongPiUtils.getCaiHongPi();

//if ("osEGp5o2TN9nqLOMMOY8WbWX-Slo".equals(lys)){
//        Weather weather = WeatherUtils.getWeather();
//
//        templateMessage.addData(new WxMpTemplateData("riqi",weather.getDate() + "  "+ weather.getWeek(),"#00BFFF"));
//        templateMessage.addData(new WxMpTemplateData("tianqi",weather.getText_now(),"#00FFFF"));
//        templateMessage.addData(new WxMpTemplateData("low",weather.getLow() + "","#173177"));
//        templateMessage.addData(new WxMpTemplateData("temp",weather.getTemp() + "","#EE212D"));
//        templateMessage.addData(new WxMpTemplateData("high",weather.getHigh()+ "","#FF6347" ));
//        templateMessage.addData(new WxMpTemplateData("windclass",weather.getWind_class()+ "","#42B857" ));
//        templateMessage.addData(new WxMpTemplateData("winddir",weather.getWind_dir()+ "","#B95EA3" ));
//
//        templateMessage.addData(new WxMpTemplateData("guokao",JiNianRiUtils.getGuoKao()+"","#c71c15"));
//        templateMessage.addData(new WxMpTemplateData("shengkao",JiNianRiUtils.getShengKao()+"","#c71c15"));
//        templateMessage.addData(new WxMpTemplateData("shengri1",JiNianRiUtils.getBirthday_Jo()+"","#FFA500"));
//
//        templateMessage.addData(new WxMpTemplateData("caiHongPi",caiHongPi+ "","#FF69B4" ));
//        templateMessage.addData(new WxMpTemplateData("title",news.get("title")+ "","#15c7b0" ));
//        templateMessage.addData(new WxMpTemplateData("digest",news.get("digest")+ "","#15c7b0" ));


    Weather weather = WeatherUtils.getWeather();
    templateMessage.addData(new WxMpTemplateData("riqi",weather.getDate() + "  "+ weather.getWeek(),"#00BFFF"));
    templateMessage.addData(new WxMpTemplateData("tianqi",weather.getText_now(),"#00FFFF"));
    templateMessage.addData(new WxMpTemplateData("low",weather.getLow() + "","#173177"));
    templateMessage.addData(new WxMpTemplateData("temp",weather.getTemp() + "","#EE212D"));
    templateMessage.addData(new WxMpTemplateData("high",weather.getHigh()+ "","#FF6347" ));
    templateMessage.addData(new WxMpTemplateData("windclass",weather.getWind_class()+ "","#42B857" ));
    templateMessage.addData(new WxMpTemplateData("winddir",weather.getWind_dir()+ "","#B95EA3" ));
    templateMessage.addData(new WxMpTemplateData("caihongpi","每日一句马屁："+caiHongPi,"#B95EA3" ));


        try {
            wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
        } catch (WxErrorException e) {
            System.out.println("发送失败！");
            e.printStackTrace();
        }

    }

}
